// GeneralPage.cpp : implementation file
/*********************************************************************
*	Author         : orbit
*	Date           : November 16, 2000
* Last-modified  : June 4, 2002 
*	Contact us     : inte2000@163.com,support@winmsg.com
*	Web Page       : http://www.winmsg.com/cn/orbit.htm (for Chinese version)
*						       http://www.winmsg.com/orbit.htm (for English version)
**********************************************************************/

#include "stdafx.h"
#include "tabbars.h"
#include "GeneralPage.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGeneralPage property page

IMPLEMENT_DYNCREATE(CGeneralPage, CPropertyPage)

//##ModelId=431C34CA035C
CGeneralPage::CGeneralPage() : CPropertyPage(CGeneralPage::IDD)
{
	//{{AFX_DATA_INIT(CGeneralPage)
	m_bAddLog = FALSE;
	m_bAddTime = FALSE;
	m_bAddUser = FALSE;
	m_bAutoSave = FALSE;
	m_bBuilds = FALSE;
	m_bCompileUser = FALSE;
	m_bEndTime = FALSE;
	m_bErrors = FALSE;
	m_bStartTime = FALSE;
	m_bWarns = FALSE;
	m_strAddUser = lpszNull;
	m_nSaveTime = 10;
	//}}AFX_DATA_INIT
}

//##ModelId=431C34CA036B
CGeneralPage::~CGeneralPage()
{
}

//##ModelId=431C34CA03BC
void CGeneralPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGeneralPage)
	DDX_Check(pDX, IDC_CHK_ADDLOG, m_bAddLog);
	DDX_Check(pDX, IDC_CHK_ADDTIME, m_bAddTime);
	DDX_Check(pDX, IDC_CHK_ADDUSER, m_bAddUser);
	DDX_Check(pDX, IDC_CHK_AUTOSAVE, m_bAutoSave);
	DDX_Check(pDX, IDC_CHK_BUILDS, m_bBuilds);
	DDX_Check(pDX, IDC_CHK_COMPILEUSER, m_bCompileUser);
	DDX_Check(pDX, IDC_CHK_ENDTIME, m_bEndTime);
	DDX_Check(pDX, IDC_CHK_ERRORS, m_bErrors);
	DDX_Check(pDX, IDC_CHK_STARTTIME, m_bStartTime);
	DDX_Check(pDX, IDC_CHK_WARNS, m_bWarns);
	DDX_Text(pDX, IDC_EDIT_ADDUSER, m_strAddUser);
	DDX_Text(pDX, IDC_EDIT_SAVETIME, m_nSaveTime);
	DDV_MinMaxInt(pDX, m_nSaveTime, 1, 100);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGeneralPage, CPropertyPage)
	//{{AFX_MSG_MAP(CGeneralPage)
	ON_EN_CHANGE(IDC_EDIT_ADDUSER, OnChangeEditAdduser)
	ON_EN_CHANGE(IDC_EDIT_SAVETIME, OnChangeEditSavetime)
	//}}AFX_MSG_MAP
	ON_CONTROL_RANGE(BN_CLICKED,IDC_CHK_ADDTIME,IDC_CHK_COMPILEUSER,OnChecksClicked)
END_MESSAGE_MAP()
//IDC_CHK_ADDTIME = 1027
//IDC_CHK_COMPILEUSER = 1036
/////////////////////////////////////////////////////////////////////////////
// CGeneralPage message handlers

//##ModelId=431C34CA03D8
BOOL CGeneralPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	CIni ini(g_szIniPathName);
	ini.GetBoolValue(lpszGeneral,lpszAddTime,m_bAddTime,g_bAddTime);
	ini.GetBoolValue(lpszGeneral,lpszAddUser,m_bAddUser,g_bAddUser);
	ini.GetValue(lpszGeneral,lpszUser,m_strAddUser,g_szUser);
	ini.GetBoolValue(lpszGeneral,lpszAutoSave,m_bAutoSave,g_bAutoSave);
	ini.GetValue(lpszGeneral,lpszTimeSpan,m_nSaveTime,g_nSaveTimeSpan);
	ini.GetBoolValue(lpszGeneral,lpszSaveLog,m_bAddLog,FALSE);
	ini.GetBoolValue(lpszGeneral,_T("bBuildTimes"),m_bBuilds,FALSE);
	ini.GetBoolValue(lpszGeneral,_T("bErrors"),m_bErrors,FALSE);
	ini.GetBoolValue(lpszGeneral,_T("bWarns"),m_bWarns,FALSE);
	ini.GetBoolValue(lpszGeneral,_T("bStartTime"),m_bStartTime,FALSE);
	ini.GetBoolValue(lpszGeneral,_T("bEndTime"),m_bEndTime,FALSE);
	ini.GetBoolValue(lpszGeneral,_T("bOperater"),m_bCompileUser,FALSE);
	ini.Clear();

	GetDlgItem(IDC_EDIT_ADDUSER)->EnableWindow(m_bAddUser);
	GetDlgItem(IDC_EDIT_SAVETIME)->EnableWindow(m_bAutoSave);

	GetDlgItem(IDC_CHK_BUILDS)->EnableWindow(m_bAddLog);
	GetDlgItem(IDC_CHK_ERRORS)->EnableWindow(m_bAddLog);
	GetDlgItem(IDC_CHK_WARNS)->EnableWindow(m_bAddLog);
	GetDlgItem(IDC_CHK_STARTTIME)->EnableWindow(m_bAddLog);
	GetDlgItem(IDC_CHK_ENDTIME)->EnableWindow(m_bAddLog);
	GetDlgItem(IDC_CHK_COMPILEUSER)->EnableWindow(m_bAddLog);


	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//##ModelId=431C34CB0002
void CGeneralPage::OnChecksClicked(int index)
{
	if(index == IDC_CHK_ADDLOG)
	{
		m_bAddLog = !m_bAddLog;
		GetDlgItem(IDC_CHK_BUILDS)->EnableWindow(m_bAddLog);
		GetDlgItem(IDC_CHK_ERRORS)->EnableWindow(m_bAddLog);
		GetDlgItem(IDC_CHK_WARNS)->EnableWindow(m_bAddLog);
		GetDlgItem(IDC_CHK_STARTTIME)->EnableWindow(m_bAddLog);
		GetDlgItem(IDC_CHK_ENDTIME)->EnableWindow(m_bAddLog);
		GetDlgItem(IDC_CHK_COMPILEUSER)->EnableWindow(m_bAddLog);
	}
	else if(index == IDC_CHK_ADDUSER)
	{
		m_bAddUser = !m_bAddUser;
		GetDlgItem(IDC_EDIT_ADDUSER)->EnableWindow(m_bAddUser);
	}
	else if(index == IDC_CHK_AUTOSAVE)
	{
		m_bAutoSave = !m_bAutoSave;
		GetDlgItem(IDC_EDIT_SAVETIME)->EnableWindow(m_bAutoSave);
	}
	SetModified();
}

//##ModelId=431C34CA03DA
void CGeneralPage::OnChangeEditAdduser() 
{
	SetModified();
}

//##ModelId=431C34CB0000
void CGeneralPage::OnChangeEditSavetime() 
{
	SetModified();
}

//##ModelId=431C34CA03BA
BOOL CGeneralPage::OnApply() 
{
	UpdateData(TRUE);
	g_bAddTime = m_bAddTime;
	g_bAddUser = m_bAddUser;
	g_nSaveTimeSpan = m_nSaveTime;
	g_bAutoSave = m_bAutoSave;
	wsprintf(g_szUser,_T("%s"),m_strAddUser);

	CIni ini(g_szIniPathName);
	ini.SetValue(lpszMainIfo,_T("sVersion"),_T("1.17"));
	ini.SetValue(lpszMainIfo,_T("sBuilds"),_T("3169"));
	
	ini.SetBoolValue(lpszGeneral,lpszAddTime,m_bAddTime);
	ini.SetBoolValue(lpszGeneral,lpszAddUser,m_bAddUser);
	ini.SetValue(lpszGeneral,lpszUser,m_strAddUser);
	ini.SetBoolValue(lpszGeneral,lpszAutoSave,m_bAutoSave);
	ini.SetValue(lpszGeneral,lpszTimeSpan,m_nSaveTime);
	ini.SetBoolValue(lpszGeneral,lpszSaveLog,m_bAddLog);
	ini.SetBoolValue(lpszGeneral,_T("bBuildTimes"),m_bBuilds);
	ini.SetBoolValue(lpszGeneral,_T("bErrors"),m_bErrors);
	ini.SetBoolValue(lpszGeneral,_T("bWarns"),m_bWarns);
	ini.SetBoolValue(lpszGeneral,_T("bStartTime"),m_bStartTime);
	ini.SetBoolValue(lpszGeneral,_T("bEndTime"),m_bEndTime);
	ini.SetBoolValue(lpszGeneral,_T("bOperater"),m_bCompileUser);
	ini.Write(g_szIniPathName);
	ini.Clear();
	
	return CPropertyPage::OnApply();
}
